import 'package:get/get.dart';
import 'package:myapp/app/data/entities/banner_model.dart';
import 'package:myapp/app/data/entities/movie_model.dart';
import 'package:myapp/app/data/repository/comm_repository.dart';
import 'package:myapp/app/data/repository/movie_repository.dart';

class MoveListController extends GetxController {

  final _commRepository = Get.find<ICommRepository>();

  final _movieRepository = Get.find<IMovieRepository>();

  final bannerList = <Banner>[].obs;

  final categoryList = <String>[].obs;

  final RxList<Map<String, List<Movie>>> movies = <Map<String, List<Movie>>>[].obs;

  // RxList<Banner> get bannerList => _bannerList;

  // RxList<String> get bannerImageList => _bannerList.map((element) => element.img).toList().obs;

  @override
  void onInit() {
    super.onInit();
  }

  @override
  void onReady() {
    super.onReady();
    // _requestBannerList();
  }

  Future<void> _requestMovieList() async {
    var data = await _movieRepository.getMovies();
    movies.clear();
    movies.value = data;
  }

  void requestMovieList() {
    _requestMovieList();
  }

  void requestCategoryList() {
    _requestCategoryList();
  }

  Future<void> _requestCategoryList() async {
    //todo 偷懒，直接写死数据。
    final data = <String>[];
    data.add("动作");
    data.add("喜剧");
    data.add("爱情");
    data.add("惊悚");
    data.add("筛选");
    await Future.value(true);
    categoryList.value = data;
  }

  Future<void> _requestBannerList() async {
    var data = await _commRepository.getBannerList();
    bannerList.clear();
    bannerList.value = data;
    print("_requestBannerList ${bannerList.length}");
  }

  void requestBannerList() {
    _requestBannerList();
  }

  @override
  void onClose() {}
}
